<template>
  <ul class="sub-nav">
    <template v-for="(item, index) in subList">
      <li :key="index" @click="actSelect(index)">{{ item.title }}</li>
    </template>
  </ul>
</template>

<script>
  export default {
    name: 'SubNav',
    props: {
      list: {
        type: Array,
        default () {
          return []
        }
      }
    },
    data () {
      return {
        subList: this.list
      }
    },
    created () {
      // this.getList()
    },
    methods: {
      async getList () {
        // let data = await this.$xhr.get('请求的 url', {})
        // if (data.code) { return }
        // 下面是业务代码
      },
      actSelect (index) {
        this.subList.forEach(element => {
          element.selected = false
        })
        this.subList[index].selected = true
        this.$emit('select')
      }
    },
    components: {}
  }
</script>

<style lang="less" rel="stylesheet/less" scoped>
  .sub-nav{
    li{
      box-sizing: border-box;
      color: rgb(255, 255, 255);
      background-color: rgba(0, 0, 0, 0.1);
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);
      font-size: 14px;
      display: block;
      padding: 0px 15px 0px 20px;
      cursor: pointer;
      &:hover{
        background-color: rgba(0, 0, 0, 0.3);
      }
    }
  }
</style>
